using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using database;
using objetos;

namespace dados
{
	#region TB_ORDER_BOOK_BUS
	/// <summary>
	/// This object represents the properties and methods of a TB_ORDER_BOOK_BUS.
	/// </summary>
	public class DAL_TB_ORDER_BOOK_BUS
	{		
	
		/// <summary>
		/// Incluir via aplicacao
		/// </summary>	
		public int Incluir(OBJ_TB_ORDER_BOOK_BUS obj)
		{
			try
			{
				DAO_DATABASE db = new DAO_DATABASE();
				DataSet ds = new DataSet();
				List<string> lista = new List<string>();		
	
				db.CreateParameter("@eol", SqlDbType.DateTime, obj.eol);				
				lista.Add("@eol");				
				db.CreateParameter("@cdd", SqlDbType.DateTime, obj.cdd);				
				lista.Add("@cdd");				
				db.CreateParameter("@mercado", SqlDbType.Int, obj.mercado);				
				lista.Add("@mercado");				
				db.CreateParameter("@bo", SqlDbType.Int, obj.bo);				
				lista.Add("@bo");				
				db.CreateParameter("@green_ok", SqlDbType.DateTime, obj.green_ok);				
				lista.Add("@green_ok");				
				db.CreateParameter("@online", SqlDbType.DateTime, obj.online);				
				lista.Add("@online");				
				db.CreateParameter("@industr_on", SqlDbType.DateTime, obj.industr_on);				
				lista.Add("@industr_on");				
				db.CreateParameter("@industr_off", SqlDbType.DateTime, obj.industr_off);				
				lista.Add("@industr_off");				
				db.CreateParameter("@dt_portaria", SqlDbType.DateTime, obj.dt_portaria);				
				lista.Add("@dt_portaria");				
				db.CreateParameter("@encarrocador", SqlDbType.VarChar, obj.encarrocador);				
				lista.Add("@encarrocador");				
				db.CreateParameter("@chassi", SqlDbType.Int, obj.chassi);				
				lista.Add("@chassi");				
				db.CreateParameter("@modelo", SqlDbType.VarChar, obj.modelo);				
				lista.Add("@modelo");				
				db.CreateParameter("@versao", SqlDbType.VarChar, obj.versao);				
				lista.Add("@versao");				
				db.CreateParameter("@aplicacao", SqlDbType.VarChar, obj.aplicacao);				
				lista.Add("@aplicacao");				
				db.CreateParameter("@ano_modelo", SqlDbType.VarChar, obj.ano_modelo);				
				lista.Add("@ano_modelo");				
				db.CreateParameter("@motor", SqlDbType.VarChar, obj.motor);				
				lista.Add("@motor");				
				db.CreateParameter("@eixo", SqlDbType.VarChar, obj.eixo);				
				lista.Add("@eixo");				
				db.CreateParameter("@entre_eixo", SqlDbType.VarChar, obj.entre_eixo);				
				lista.Add("@entre_eixo");				
				db.CreateParameter("@caixa", SqlDbType.VarChar, obj.caixa);				
				lista.Add("@caixa");				
				db.CreateParameter("@fabrica", SqlDbType.VarChar, obj.fabrica);				
				lista.Add("@fabrica");				
				db.CreateParameter("@driver", SqlDbType.VarChar, obj.driver);				
				lista.Add("@driver");				
				db.CreateParameter("@eixo_traseiro", SqlDbType.VarChar, obj.eixo_traseiro);				
				lista.Add("@eixo_traseiro");				
				db.CreateParameter("@abs", SqlDbType.VarChar, obj.abs);				
				lista.Add("@abs");				
				db.CreateParameter("@freio", SqlDbType.VarChar, obj.freio);				
				lista.Add("@freio");				
				db.CreateParameter("@pneu", SqlDbType.VarChar, obj.pneu);				
				lista.Add("@pneu");				
				db.CreateParameter("@modelo_pneu", SqlDbType.VarChar, obj.modelo_pneu);				
				lista.Add("@modelo_pneu");				
				db.CreateParameter("@cliente_original", SqlDbType.VarChar, obj.cliente_original);				
				lista.Add("@cliente_original");				
				db.CreateParameter("@prom_entrada", SqlDbType.VarChar, obj.prom_entrada);				
				lista.Add("@prom_entrada");				
				db.CreateParameter("@cliente_final", SqlDbType.VarChar, obj.cliente_final);				
				lista.Add("@cliente_final");				
				db.CreateParameter("@cnpj", SqlDbType.VarChar, obj.cnpj);				
				lista.Add("@cnpj");				
				db.CreateParameter("@status", SqlDbType.VarChar, obj.status);				
				lista.Add("@status");				
				db.CreateParameter("@filial", SqlDbType.VarChar, obj.filial);				
				lista.Add("@filial");				
				db.CreateParameter("@consultor", SqlDbType.VarChar, obj.consultor);				
				lista.Add("@consultor");				
				db.CreateParameter("@valor", SqlDbType.VarChar, obj.valor);				
				lista.Add("@valor");				
				db.CreateParameter("@comissao", SqlDbType.VarChar, obj.comissao);				
				lista.Add("@comissao");				
				db.CreateParameter("@modalidade", SqlDbType.VarChar, obj.modalidade);				
				lista.Add("@modalidade");				
				db.CreateParameter("@financeira", SqlDbType.VarChar, obj.financeira);				
				lista.Add("@financeira");				
				db.CreateParameter("@previsao_fat", SqlDbType.DateTime, obj.previsao_fat);				
				lista.Add("@previsao_fat");				
				db.CreateParameter("@pendencia", SqlDbType.VarChar, obj.pendencia);				
				lista.Add("@pendencia");				
				db.CreateParameter("@observacao", SqlDbType.VarChar, obj.observacao);				
				lista.Add("@observacao");				
				db.CreateParameter("@cred_aprovado_banco", SqlDbType.VarChar, obj.cred_aprovado_banco);				
				lista.Add("@cred_aprovado_banco");				
				db.CreateParameter("@prot_bnds", SqlDbType.VarChar, obj.prot_bnds);				
				lista.Add("@prot_bnds");				
				db.CreateParameter("@dt_prot_banco_bnds", SqlDbType.DateTime, obj.dt_prot_banco_bnds);				
				lista.Add("@dt_prot_banco_bnds");				
				db.CreateParameter("@autorizacao_fat", SqlDbType.VarChar, obj.autorizacao_fat);				
				lista.Add("@autorizacao_fat");				
				db.CreateParameter("@prioridade", SqlDbType.VarChar, obj.prioridade);				
				lista.Add("@prioridade");				
				db.CreateParameter("@diferenca", SqlDbType.VarChar, obj.diferenca);				
				lista.Add("@diferenca");				
				db.CreateParameter("@dt_solicitacao_ab12", SqlDbType.DateTime, obj.dt_solicitacao_ab12);				
				lista.Add("@dt_solicitacao_ab12");				
				db.CreateParameter("@id_usuario", SqlDbType.Int, obj.id_usuario);				
				lista.Add("@id_usuario");				
				db.CreateParameter("@dt_importacao", SqlDbType.DateTime, obj.dt_importacao);				
				lista.Add("@dt_importacao");				
	
				string query = String.Format("Insert Into tb_order_book_bus ({0}) Values ({1}); SELECT SCOPE_IDENTITY()",  string.Join(",",lista.ToArray()).ToString().Replace("@", ""), string.Join(",",lista.ToArray()).ToString());
				ds = db.ExecuteQuery(query);
				
				return Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
			}
			catch (Exception)
       		{
            	throw;
        	}
		}
		
		/// <summary>
		/// Update via aplicacao
		/// </summary>			
		public void Alterar(OBJ_TB_ORDER_BOOK_BUS obj)
		{
			try
			{
				DAO_DATABASE db = new DAO_DATABASE();
				List<string> lista = new List<string>();
	
				db.CreateParameter("@id", SqlDbType.Int, obj.id);
				
	
				db.CreateParameter("@eol", SqlDbType.DateTime, obj.eol);
				lista.Add("eol = @eol");
				db.CreateParameter("@cdd", SqlDbType.DateTime, obj.cdd);
				lista.Add("cdd = @cdd");
				db.CreateParameter("@mercado", SqlDbType.Int, obj.mercado);
				lista.Add("mercado = @mercado");
				db.CreateParameter("@bo", SqlDbType.Int, obj.bo);
				lista.Add("bo = @bo");
				db.CreateParameter("@green_ok", SqlDbType.DateTime, obj.green_ok);
				lista.Add("green_ok = @green_ok");
				db.CreateParameter("@online", SqlDbType.DateTime, obj.online);
				lista.Add("online = @online");
				db.CreateParameter("@industr_on", SqlDbType.DateTime, obj.industr_on);
				lista.Add("industr_on = @industr_on");
				db.CreateParameter("@industr_off", SqlDbType.DateTime, obj.industr_off);
				lista.Add("industr_off = @industr_off");
				db.CreateParameter("@dt_portaria", SqlDbType.DateTime, obj.dt_portaria);
				lista.Add("dt_portaria = @dt_portaria");
				db.CreateParameter("@encarrocador", SqlDbType.VarChar, obj.encarrocador);
				lista.Add("encarrocador = @encarrocador");
				db.CreateParameter("@chassi", SqlDbType.Int, obj.chassi);
				lista.Add("chassi = @chassi");
				db.CreateParameter("@modelo", SqlDbType.VarChar, obj.modelo);
				lista.Add("modelo = @modelo");
				db.CreateParameter("@versao", SqlDbType.VarChar, obj.versao);
				lista.Add("versao = @versao");
				db.CreateParameter("@aplicacao", SqlDbType.VarChar, obj.aplicacao);
				lista.Add("aplicacao = @aplicacao");
				db.CreateParameter("@ano_modelo", SqlDbType.VarChar, obj.ano_modelo);
				lista.Add("ano_modelo = @ano_modelo");
				db.CreateParameter("@motor", SqlDbType.VarChar, obj.motor);
				lista.Add("motor = @motor");
				db.CreateParameter("@eixo", SqlDbType.VarChar, obj.eixo);
				lista.Add("eixo = @eixo");
				db.CreateParameter("@entre_eixo", SqlDbType.VarChar, obj.entre_eixo);
				lista.Add("entre_eixo = @entre_eixo");
				db.CreateParameter("@caixa", SqlDbType.VarChar, obj.caixa);
				lista.Add("caixa = @caixa");
				db.CreateParameter("@fabrica", SqlDbType.VarChar, obj.fabrica);
				lista.Add("fabrica = @fabrica");
				db.CreateParameter("@driver", SqlDbType.VarChar, obj.driver);
				lista.Add("driver = @driver");
				db.CreateParameter("@eixo_traseiro", SqlDbType.VarChar, obj.eixo_traseiro);
				lista.Add("eixo_traseiro = @eixo_traseiro");
				db.CreateParameter("@abs", SqlDbType.VarChar, obj.abs);
				lista.Add("abs = @abs");
				db.CreateParameter("@freio", SqlDbType.VarChar, obj.freio);
				lista.Add("freio = @freio");
				db.CreateParameter("@pneu", SqlDbType.VarChar, obj.pneu);
				lista.Add("pneu = @pneu");
				db.CreateParameter("@modelo_pneu", SqlDbType.VarChar, obj.modelo_pneu);
				lista.Add("modelo_pneu = @modelo_pneu");
				db.CreateParameter("@cliente_original", SqlDbType.VarChar, obj.cliente_original);
				lista.Add("cliente_original = @cliente_original");
				db.CreateParameter("@prom_entrada", SqlDbType.VarChar, obj.prom_entrada);
				lista.Add("prom_entrada = @prom_entrada");
				db.CreateParameter("@cliente_final", SqlDbType.VarChar, obj.cliente_final);
				lista.Add("cliente_final = @cliente_final");
				db.CreateParameter("@cnpj", SqlDbType.VarChar, obj.cnpj);
				lista.Add("cnpj = @cnpj");
				db.CreateParameter("@status", SqlDbType.VarChar, obj.status);
				lista.Add("status = @status");
				db.CreateParameter("@filial", SqlDbType.VarChar, obj.filial);
				lista.Add("filial = @filial");
				db.CreateParameter("@consultor", SqlDbType.VarChar, obj.consultor);
				lista.Add("consultor = @consultor");
				db.CreateParameter("@valor", SqlDbType.VarChar, obj.valor);
				lista.Add("valor = @valor");
				db.CreateParameter("@comissao", SqlDbType.VarChar, obj.comissao);
				lista.Add("comissao = @comissao");
				db.CreateParameter("@modalidade", SqlDbType.VarChar, obj.modalidade);
				lista.Add("modalidade = @modalidade");
				db.CreateParameter("@financeira", SqlDbType.VarChar, obj.financeira);
				lista.Add("financeira = @financeira");
				db.CreateParameter("@previsao_fat", SqlDbType.DateTime, obj.previsao_fat);
				lista.Add("previsao_fat = @previsao_fat");
				db.CreateParameter("@pendencia", SqlDbType.VarChar, obj.pendencia);
				lista.Add("pendencia = @pendencia");
				db.CreateParameter("@observacao", SqlDbType.VarChar, obj.observacao);
				lista.Add("observacao = @observacao");
				db.CreateParameter("@cred_aprovado_banco", SqlDbType.VarChar, obj.cred_aprovado_banco);
				lista.Add("cred_aprovado_banco = @cred_aprovado_banco");
				db.CreateParameter("@prot_bnds", SqlDbType.VarChar, obj.prot_bnds);
				lista.Add("prot_bnds = @prot_bnds");
				db.CreateParameter("@dt_prot_banco_bnds", SqlDbType.DateTime, obj.dt_prot_banco_bnds);
				lista.Add("dt_prot_banco_bnds = @dt_prot_banco_bnds");
				db.CreateParameter("@autorizacao_fat", SqlDbType.VarChar, obj.autorizacao_fat);
				lista.Add("autorizacao_fat = @autorizacao_fat");
				db.CreateParameter("@prioridade", SqlDbType.VarChar, obj.prioridade);
				lista.Add("prioridade = @prioridade");
				db.CreateParameter("@diferenca", SqlDbType.VarChar, obj.diferenca);
				lista.Add("diferenca = @diferenca");
				db.CreateParameter("@dt_solicitacao_ab12", SqlDbType.DateTime, obj.dt_solicitacao_ab12);
				lista.Add("dt_solicitacao_ab12 = @dt_solicitacao_ab12");
				db.CreateParameter("@id_usuario", SqlDbType.Int, obj.id_usuario);
				lista.Add("id_usuario = @id_usuario");
				db.CreateParameter("@dt_importacao", SqlDbType.DateTime, obj.dt_importacao);
				lista.Add("dt_importacao = @dt_importacao");
	
				string query = String.Format("Update TB_ORDER_BOOK_BUS Set {0} Where id = @id", string.Join(",",lista.ToArray()).ToString());
				db.ExecuteQuery(query);
			}
			catch (Exception)
       		{
            	throw;
        	}
		}	
		
		/// <summary>
		/// Delete viaaplicacao
		/// </summary>	
		public void Excluir(OBJ_TB_ORDER_BOOK_BUS obj)
		{
			try
			{
				DAO_DATABASE db = new DAO_DATABASE();
				StringBuilder queryParameters = new StringBuilder();
				db.CreateParameter("@id", SqlDbType.Int, obj.id);
		
				string query = "Delete tb_order_book_bus Where id = @id";			
				db.ExecuteQuery(query);
			}
			catch (Exception)
       		{
            	throw;
        	}
		}
	
	
		/// <summary>
		/// Lista objeto
		/// </summary>						
		public List<OBJ_TB_ORDER_BOOK_BUS> SelecionarLista()
    	{
        	try
        	{
				DAO_DATABASE db = new DAO_DATABASE();
				List<OBJ_TB_ORDER_BOOK_BUS> lista = new List<OBJ_TB_ORDER_BOOK_BUS>();
				OBJ_TB_ORDER_BOOK_BUS obj = null;
				DataTable dt = new DataTable();
				DataSet ds = new DataSet();
				StringBuilder sb = new StringBuilder();
				sb.Append("Select * from  TB_ORDER_BOOK_BUS ");
        
	            ds = db.ExecuteQuery(sb.ToString());
				
				if(!db.DataSetIsEmpty(ds))
				{
					dt = ds.Tables[0];
					
					foreach (DataRow dr in dt.Rows)
					{											
						obj = new OBJ_TB_ORDER_BOOK_BUS();
						Set(obj,dr);
						lista.Add(obj);
		
					}
				}
				return lista;
        	}
        	catch (Exception)
       		{
            	throw;
        	}

    	}
		
		/// <summary>
		/// Set Objeto
		/// </summary>	
		private void Set(OBJ_TB_ORDER_BOOK_BUS obj,DataRow dr)
		{
			obj.id = Convert.ToInt32(dr["id"]);						
			obj.eol = dr["eol"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["eol"].ToString()) ;						
			obj.cdd = dr["cdd"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["cdd"].ToString()) ;						
			obj.mercado = Convert.ToInt32(dr["mercado"].ToString()) ;	
			obj.bo = Convert.ToInt32(dr["bo"].ToString()) ;	
			obj.green_ok = dr["green_ok"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["green_ok"].ToString()) ;						
			obj.online = dr["online"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["online"].ToString()) ;						
			obj.industr_on = dr["industr_on"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["industr_on"].ToString()) ;						
			obj.industr_off = dr["industr_off"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["industr_off"].ToString()) ;						
			obj.dt_portaria = dr["dt_portaria"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["dt_portaria"].ToString()) ;						
			obj.encarrocador = dr["encarrocador"] == DBNull.Value ?  string.Empty : dr["encarrocador"].ToString() ;
			obj.chassi = Convert.ToInt32(dr["chassi"].ToString()) ;	
			obj.modelo = dr["modelo"] == DBNull.Value ?  string.Empty : dr["modelo"].ToString() ;
			obj.versao = dr["versao"] == DBNull.Value ?  string.Empty : dr["versao"].ToString() ;
			obj.aplicacao = dr["aplicacao"] == DBNull.Value ?  string.Empty : dr["aplicacao"].ToString() ;
			obj.ano_modelo = dr["ano_modelo"] == DBNull.Value ?  string.Empty : dr["ano_modelo"].ToString() ;
			obj.motor = dr["motor"] == DBNull.Value ?  string.Empty : dr["motor"].ToString() ;
			obj.eixo = dr["eixo"] == DBNull.Value ?  string.Empty : dr["eixo"].ToString() ;
			obj.entre_eixo = dr["entre_eixo"] == DBNull.Value ?  string.Empty : dr["entre_eixo"].ToString() ;
			obj.caixa = dr["caixa"] == DBNull.Value ?  string.Empty : dr["caixa"].ToString() ;
			obj.fabrica = dr["fabrica"] == DBNull.Value ?  string.Empty : dr["fabrica"].ToString() ;
			obj.driver = dr["driver"] == DBNull.Value ?  string.Empty : dr["driver"].ToString() ;
			obj.eixo_traseiro = dr["eixo_traseiro"] == DBNull.Value ?  string.Empty : dr["eixo_traseiro"].ToString() ;
			obj.abs = dr["abs"] == DBNull.Value ?  string.Empty : dr["abs"].ToString() ;
			obj.freio = dr["freio"] == DBNull.Value ?  string.Empty : dr["freio"].ToString() ;
			obj.pneu = dr["pneu"] == DBNull.Value ?  string.Empty : dr["pneu"].ToString() ;
			obj.modelo_pneu = dr["modelo_pneu"] == DBNull.Value ?  string.Empty : dr["modelo_pneu"].ToString() ;
			obj.cliente_original = dr["cliente_original"] == DBNull.Value ?  string.Empty : dr["cliente_original"].ToString() ;
			obj.prom_entrada = dr["prom_entrada"] == DBNull.Value ?  string.Empty : dr["prom_entrada"].ToString() ;
			obj.cliente_final = dr["cliente_final"] == DBNull.Value ?  string.Empty : dr["cliente_final"].ToString() ;
			obj.cnpj = dr["cnpj"] == DBNull.Value ?  string.Empty : dr["cnpj"].ToString() ;
			obj.status = dr["status"] == DBNull.Value ?  string.Empty : dr["status"].ToString() ;
			obj.filial = dr["filial"] == DBNull.Value ?  string.Empty : dr["filial"].ToString() ;
			obj.consultor = dr["consultor"] == DBNull.Value ?  string.Empty : dr["consultor"].ToString() ;
			obj.valor = dr["valor"] == DBNull.Value ?  string.Empty : dr["valor"].ToString() ;
			obj.comissao = dr["comissao"] == DBNull.Value ?  string.Empty : dr["comissao"].ToString() ;
			obj.modalidade = dr["modalidade"] == DBNull.Value ?  string.Empty : dr["modalidade"].ToString() ;
			obj.financeira = dr["financeira"] == DBNull.Value ?  string.Empty : dr["financeira"].ToString() ;
			obj.previsao_fat = dr["previsao_fat"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["previsao_fat"].ToString()) ;						
			obj.pendencia = dr["pendencia"] == DBNull.Value ?  string.Empty : dr["pendencia"].ToString() ;
			obj.observacao = dr["observacao"] == DBNull.Value ?  string.Empty : dr["observacao"].ToString() ;
			obj.cred_aprovado_banco = dr["cred_aprovado_banco"] == DBNull.Value ?  string.Empty : dr["cred_aprovado_banco"].ToString() ;
			obj.prot_bnds = dr["prot_bnds"] == DBNull.Value ?  string.Empty : dr["prot_bnds"].ToString() ;
			obj.dt_prot_banco_bnds = dr["dt_prot_banco_bnds"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["dt_prot_banco_bnds"].ToString()) ;						
			obj.autorizacao_fat = dr["autorizacao_fat"] == DBNull.Value ?  string.Empty : dr["autorizacao_fat"].ToString() ;
			obj.prioridade = dr["prioridade"] == DBNull.Value ?  string.Empty : dr["prioridade"].ToString() ;
			obj.diferenca = dr["diferenca"] == DBNull.Value ?  string.Empty : dr["diferenca"].ToString() ;
			obj.dt_solicitacao_ab12 = dr["dt_solicitacao_ab12"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["dt_solicitacao_ab12"].ToString()) ;						
			obj.id_usuario = Convert.ToInt32(dr["id_usuario"].ToString()) ;	
			obj.dt_importacao = dr["dt_importacao"] == DBNull.Value ? (DateTime?)null :  Convert.ToDateTime(dr["dt_importacao"].ToString()) ;						
			
		}						
				
		/// <summary>
		/// Selecionar Objeto Por ID
		/// </summary>	
		public OBJ_TB_ORDER_BOOK_BUS SelecionarObjetoPorId(int id)
		{
			try
			{
				DAO_DATABASE db = new DAO_DATABASE();
				OBJ_TB_ORDER_BOOK_BUS obj = new OBJ_TB_ORDER_BOOK_BUS();
				DataSet ds = new DataSet();				
				DataTable dt = new DataTable();
				
				db.CreateParameter("@id", SqlDbType.Int, id);
				StringBuilder sb = new StringBuilder();
				sb.Append("SELECT * FROM tb_order_book_bus  Where id = @id");
				ds = db.ExecuteQuery(sb.ToString());				
				
				if(!db.DataSetIsEmpty(ds))
				{
					dt = ds.Tables[0];
					
					foreach (DataRow dr in dt.Rows)
                	{
						obj = new OBJ_TB_ORDER_BOOK_BUS();
						Set(obj,dr);																			
					}
					return obj;
					
				}
				else
				{
					return null;	
				}			
			}
			catch (Exception)
       		{
            	throw;
        	}
			
		}
					
		
		
		/// <summary>
		/// Lista objeto Parametro Where OrderBy
		/// </summary>							
		public List<OBJ_TB_ORDER_BOOK_BUS> SelecionarLista(String Where, String OrderBy)
    	{
        	try
        	{
				DAO_DATABASE db = new DAO_DATABASE();
				OBJ_TB_ORDER_BOOK_BUS obj = null;
				DataSet ds = new DataSet();
				DataTable dt = new DataTable();
				List<OBJ_TB_ORDER_BOOK_BUS> lista = new List<OBJ_TB_ORDER_BOOK_BUS>();
				
				StringBuilder sb = new StringBuilder();
				db.CreateParameter("@Where",SqlDbType.VarChar, Where );
				db.CreateParameter("@OrderBy", SqlDbType.VarChar, OrderBy );				
				
				sb.Append("SELECT * ");
				sb.Append(" FROM TB_ORDER_BOOK_BUS");
				if(Where != string.Empty)				
				sb.Append(string.Format(" Where {0} ",Where));
				if(OrderBy != string.Empty)
				sb.Append(string.Format(" Order by {0}",OrderBy));
				
				ds = db.ExecuteQuery(sb.ToString());
				
				if(!db.DataSetIsEmpty(ds))
				{
					dt = ds.Tables[0];
					foreach (DataRow dr in dt.Rows)
					{						
						obj = new OBJ_TB_ORDER_BOOK_BUS();
						Set(obj,dr);			
						lista.Add(obj);
					}
				}
				return lista;
        	}
        	catch (Exception)
       		{
            	throw;
        	}

    	}

		
		public DataSet Selecionar(String Where, String OrderBy, int PageIndex, int PageSize )
		{
				DAO_DATABASE db = new DAO_DATABASE();
				DataSet ds = new DataSet();
				
				StringBuilder sb = new StringBuilder();
				
				PageIndex = PageSize * PageIndex;
            	PageSize =  PageIndex + PageSize;
				
		      	if (OrderBy == string.Empty) OrderBy = "tb_order_book_bus.id";

            	sb.Append("SELECT * FROM ");
            	sb.Append(string.Format(" (SELECT ROW_NUMBER() OVER (ORDER BY {0}) AS RowNumber,",OrderBy));
           		sb.Append(" * FROM   tb_order_book_bus ");
				if (Where != string.Empty)
				{
					sb.Append(string.Format(" WHERE {0}", Where));
				}
				sb.Append(" ) query  ");
				sb.Append(string.Format(" WHERE RowNumber BETWEEN {0} + 1 and {1}; ",PageIndex,PageSize));

            	sb.Append("SELECT count(*) FROM tb_order_book_bus");
				if (Where != string.Empty)
				{
					sb.Append(string.Format(" WHERE {0}", Where));
				}
				ds = db.ExecuteQuery(sb.ToString());
				
				if (!db.DataSetIsEmpty(ds))
            	{
                publico.PUB_PAGINACAO.CalcularTotalDePaginas(Convert.ToDecimal(ds.Tables[1].Rows[0][0].ToString()));
            	}

				
            	return ds;
								
		}
				
								
		public DataSet Selecionar(String Where, String OrderBy)
        {
            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();

            sb.Append("Select * from  TB_ORDER_BOOK_BUS ");
           if (Where != string.Empty)
            {
                db.CreateParameter("@Where", SqlDbType.VarChar, Where);
                sb.Append(string.Format(" Where  {0}",Where));
            }

            if (OrderBy != string.Empty)
            {
                db.CreateParameter("@OrderBy", SqlDbType.VarChar, OrderBy);
                sb.Append(string.Format(" Order By {0}", OrderBy));
            }

            ds = db.ExecuteQuery(sb.ToString());
            return ds;
        }		
		
		public DataSet Selecionar()
        {
            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();

            sb.Append("Select * from  TB_ORDER_BOOK_BUS Order By id");            
            ds = db.ExecuteQuery(sb.ToString());
            return ds;
        }		
		
		
		public DataSet ListaCampos()
        {

            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT TABLE_NAME, ORDINAL_POSITION, ");
            sb.Append(" COLUMN_NAME, DATA_TYPE, IS_NULLABLE ");
            sb.Append(" FROM INFORMATION_SCHEMA.COLUMNS");
            sb.Append(" WHERE TABLE_NAME = 'tb_order_book_bus'");
            ds = db.ExecuteQuery(sb.ToString());

            return ds;

        }

		public DataSet DropdownList()
        {
            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();
			sb.Append("SELECT ");
			sb.Append(" id ");
				sb.Append(", eol ");  				
				sb.Append(", cdd ");  				
				sb.Append(", mercado ");  				
			sb.Append(" FROM tb_order_book_bus ");           
			sb.Append(" ORDER BY eol ");
            ds = db.ExecuteQuery(sb.ToString());

            // ds = db.ExecuteProcedure("USP_TB_ORDER_BOOK_BUS_DROPDOWNLIST");  
            return ds;
        }

        public DataSet DropdownList(String Where)
        {
            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();
            db.CreateParameter("@Where", SqlDbType.VarChar, Where);
			sb.Append("SELECT ");
			sb.Append(" id ");
			
			
			sb.Append(", eol ");  				
			
			
			sb.Append(", cdd ");  				
			
			
			sb.Append(", mercado ");  				
			sb.Append(" FROM tb_order_book_bus ");
			sb.Append(string.Format(" WHERE {0} ",Where));
			sb.Append(" ORDER BY eol ");
            ds = db.ExecuteQuery(sb.ToString());

            // ds = db.ExecuteProcedure("USP_TB_ORDER_BOOK_BUS_DROPDOWNLIST");
            return ds;
        }
		
		  public DataSet DropdownList(String Where, String OrderBy)
        {
            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();
            StringBuilder sb = new StringBuilder();
            db.CreateParameter("@Where", SqlDbType.VarChar, Where);
			sb.Append("SELECT ");
			sb.Append(" id ");
			sb.Append(", eol ");  				
			sb.Append(", cdd ");  				
			sb.Append(", mercado ");  				
			sb.Append(" FROM tb_order_book_bus ");
			sb.Append(string.Format(" WHERE {0} ORDER BY {1}",Where,OrderBy));			
            ds = db.ExecuteQuery(sb.ToString());

            // ds = db.ExecuteProcedure("USP_TB_ORDER_BOOK_BUS_DROPDOWNLIST");
            return ds;
        }

	}
	#endregion
}

